﻿@{
    Layout = null;
}


@*<div><h1 style="margin:100px auto;text-align:center;color:white;font-size:30px;font-weight:bold;">ĐĂNG NHẬP</h1></div>*@
<style type="text/css">
    #login-holder {
        background: gainsboro;
        padding: 10px;
        /*border-bottom-right-radius: 10px;
        border-top-left-radius: 10px;*/
        margin: 0 auto;
    }
    #loginbox, #forgotbox {
        padding:5px;
    }
    .forgot-pwd, .back-login {
        text-decoration:underline;
        cursor:pointer;        
    }
    .forgot-pwd:hover, .back-login:hover{
        color:red;
        cursor:pointer;
    }
    #external-login {
        cursor: pointer;
    }
</style>
<div class="titlenews">ĐĂNG NHẬP</div>
<div id="login-holder">
    <div class="clear"></div>

    <!--  start loginbox ................................................................................. -->
    <div id="loginbox">

        <!--  start login-inner -->
        <div id="login-inner">
            <div><span style="font-size:14px;font-style:italic;color:red;" id="message"></span></div>
            <table border="0" cellpadding="0" cellspacing="0">
                <tr>
                    <th>Username</th>
                    <td>
                        <input type="text" id="tendangnhap" class="login-inp" /></td>
                </tr>
                <tr>
                    <th>Password</th>
                    <td>
                        <input id="matkhau" type="password" value="" onfocus="this.value=''" class="login-inp" /></td>
                </tr>
                <tr>
                    <th></th>
                    <td valign="top">
                        <input type="checkbox" class="checkbox-size" id="login-check" /><label for="login-check">Ghi nhớ?</label></td>
                </tr>
                <tr>
                    <th></th>
                    <td>
                        <input type="button" id="dangnhap" value="Đăng Nhập" class="submit-login" /></td>
                </tr>
            </table>
        </div>
        <!--  end login-inner -->
        <div class="clear"></div>
        @*<span class="forgot-pwd">Forgot Password?</span>*@
        <div class="clear"></div>
        <span id="external-login">Đăng nhập bằng tài khoản Gmail UIT</span>
    </div>
    <!--  end loginbox -->

    <!--  start forgotbox ................................................................................... -->
    <div id="forgotbox">
        <div id="forgotbox-text">Please send us your email and we'll reset your password.</div>
        <!--  start forgot-inner -->
        <div id="forgot-inner">
            <table border="0" cellpadding="0" cellspacing="0">
                <tr>
                    <th>Email address:</th>
                    <td>
                        <input type="text" value="" class="login-inp" /></td>
                </tr>
                <tr>
                    <th></th>
                    <td>
                        <input type="button" value="Gửi" class="submit-login" /></td>
                </tr>
            </table>
        </div>
        <!--  end forgot-inner -->
        <div class="clear"></div>
        <span class="back-login">Back to login</span>
    </div>
    <!--  end forgotbox -->
    <input type="hidden" value="false" id="isGiangVien" />
</div>
<!-- End: login-holder -->
<script>
    $(document).ready(function () {
        $('#forgotbox').hide();
        $('#dangnhap').click(function () {
            $('#message').html("");
            var tendangnhap = $('#tendangnhap').val();
            var matkhau = $('#matkhau').val();
            var isGiangVien = $('#isGiangVien').val();
            if (tendangnhap == "" || matkhau == "") {
                $('#message').html("Tên Đăng Nhập và Mật Khẩu Không Được Rỗng!");
            }
            else {
                $.post("/DangNhapClient/SinhVienDangNhap", { taiKhoanDangNhap: tendangnhap, matKhau: matkhau, isGiangVien: isGiangVien },
                    function (data) {
                        if (data.success == true) {
                            //alert("Đăng Nhập Thành Công User:" + data.name);
                            window.location = "/SinhVien/index";
                        }
                        else {
                            $('#message').html(data.name);
                        }
                    });
            }

        });
        $('#loginbox input').bind('keypress', function (e) {
            if (e.keyCode == 13) {
                $('#dangnhap').click();
            }
        });
        $('.forgot-pwd').click(function () {
            $('#loginbox').hide(300);
            $('#forgotbox').show(300);
        });
        $('.back-login').click(function () {
            $('#forgotbox').hide(300);
            $('#loginbox').show(300);
        });
        $('#tendangnhap').focus();

        $("#external-login").bind("click", function () {
            document.location = "/DangNhapClient/ExternalLogin?isSinhVien=true";
        });

        $('#login-check').change(function () {
            var isChecked = $(this).is(":checked");
            if (isChecked) {
                toMem(10);
            } else {
                delMem();
            }
        });

    });
</script>

<script type="text/javascript">
    function newCookie(name, value, days) {
        var days = 10;   // the number at the left reflects the number of days for the cookie to last
        // modify it according to your needs
        if (days) {
            var date = new Date();
            date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
            var expires = "; expires=" + date.toGMTString();
        }
        else var expires = "";
        document.cookie = name + "=" + value + expires + "; path=/";
        //alert(name+value+days);
    }

    function readCookie(name) {
        var nameSG = name + "=";
        var nuller = '';
        if (document.cookie.indexOf(nameSG) == -1)
            return nuller;

        var ca = document.cookie.split(';');
        for (var i = 0; i < ca.length; i++) {
            var c = ca[i];
            while (c.charAt(0) == ' ') c = c.substring(1, c.length);
            if (c.indexOf(nameSG) == 0) return c.substring(nameSG.length, c.length);
        }
        return null;
    }

    function eraseCookie(name) {
        newCookie(name, "", 1);
    }

    function toMem(a) {        
        newCookie('uitsvtendangnhap', $("#tendangnhap").val(), a);     // add a new cookie as shown at left for every
        newCookie('uitsvmatkhau', $("#matkhau").val(), a);   // field you wish to have the script remember
    }

    function delMem(a) {
        eraseCookie('uitsvtendangnhap');   // make sure to add the eraseCookie function for every field
        eraseCookie('uitsvmatkhau');

        $("#tendangnhap").val("");   // add a line for every field
        $("#matkhau").val("");
    }


    function remCookie() {
        //alert(readCookie("uitsvtendangnhap"));
        $("#tendangnhap").val(readCookie("uitsvtendangnhap"));
        $("#matkhau").val(readCookie("uitsvmatkhau"));
    }

    function addLoadEvent(func) {
        var oldonload = window.onload;
        if (typeof window.onload != 'function') {
            window.onload = func;
        } else {
            window.onload = function () {
                if (oldonload) {
                    oldonload();
                }
                func();

            }
        }
    }

    addLoadEvent(function () {
        setTimeout(function () {
            remCookie();
        }, 1000);        
    });

</script>